package com.boe.common.util.freemark.base;

import lombok.*;
import com.boe.common.util.freemark.P0Error;
import com.boe.common.util.freemark.BaseMethodModelFreemarker;
import freemarker.template.TemplateModelException;

import java.lang.reflect.Field;
import java.util.List;

public class FreemarkerIsRes extends BaseMethodModelFreemarker {
    @Override
    public Object exec(List list) throws TemplateModelException {
        var paramValue = getFreemarkerParameter(list.get(0));

        if (paramValue instanceof Field) {
            var type = ((Field) paramValue).getType();
            return type.isEnum() ||
                    type == Boolean.class;
        } else if (paramValue instanceof Class) {
            var clz =(Class) paramValue;
            return  clz.isEnum() || clz == Boolean.class;
        }
        throw  new P0Error(paramValue);
    }
}